<template>
    <view class="content">
        <input-item custom name="Pay Certificate">
            <image-uploader fileName="payCertificate" type="info" @change="handleUpload"></image-uploader>
        </input-item>
        <input-item name="Amount">
            <input type="digit" v-model="money" />
        </input-item>
        <view class="flex-center">
            <u-button type="primary" :text="$t('submit.submitButton')" @click="submit"></u-button>
        </view>
    </view>
</template>

<script>
import { goBack, showAlert, showSuccess } from '../../../lib/helper';
import { updateOrder } from '../../../lib/service';
export default {
    data() {
        return {
            id: '',
            imageUrl: '',
            money: 0
        };
    },
    onLoad(options) {
        this.id = options.id;
    },

    methods: {
        handleUpload(data) {
            var file = data[0];
            this.imageUrl = file ? file.url : '';
        },
        submit() {
            if (!this.imageUrl) {
                showAlert('Pay certificate cannot be empty');
                return;
            }
            uni.showLoading();
            updateOrder(this.id, { payCertificateUrl: this.imageUrl, totalAmount: this.money, payStatus: 2, status: 3 })
                .then((res) => {
                    uni.hideLoading();
                    showSuccess();
                    setTimeout(() => {
                        goBack();
                    }, 480);
                })
                .catch((err) => {
                    uni.hideLoading();
                });
        },
        back() {
            uni.navigateTo({
                url: '/pages/detail/detail?id=' + this.id
            });
        }
    }
};
</script>

<style></style>
